def reverse(num):
    """

    reverse num
    Cases: 1. overflow 2. num ends with 0
    :type num: int
    :rtype: int
    """

    minus = num < 0;

    absol = abs(num);
    quotient = absol;
    newNum = 0;
    while quotient != 0:
        rem = quotient % 10;
        newNum = newNum * 10 + rem;
        quotient = quotient // 10;

    if minus:
        newNum = -newNum;
    return newNum;

def reversePy(num):
    minus = num < 0;

    digits = list(str(abs(num)));
    digits.reverse();

    newNum = int(''.join(digits));
    if minus:
        newNum = -newNum;
    return newNum;
